package com.gt.controller.user;


import com.gt.context.BaseContext;
import com.gt.pojo.Result;
import com.gt.pojo.dto.EmployeeDTO;
import com.gt.pojo.dto.UpdatePasswordDTO;
import com.gt.pojo.entity.Employee;
import com.gt.pojo.vo.EmployeeVO;
import com.gt.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/user/user")
@Api(tags = "用户信息接口")
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/auth")
    @ApiOperation("用户信息展示")
    public Result<EmployeeVO> list(){
        Employee employee = userService.auth();
        EmployeeVO employeeVO = EmployeeVO.builder()
                .id(BaseContext.getCurrentId())
                .avatar(employee.getAvatar())
                .email(employee.getEmail())
                .phone(employee.getPhone())
                .name(employee.getName())
                .username(employee.getUsername())
                .sex(employee.getSex())
                .role(employee.getRole())
                .build();
        return Result.success(employeeVO);
    }
    @PutMapping
    @ApiOperation("用户修改信息")
    public Result update(@RequestBody EmployeeDTO employeeDTO){
            userService.update(employeeDTO);
            return Result.success();
    }
    @PutMapping("/updatePassword")
    @ApiOperation("用户修改密码")
    public Result updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO){
        userService.updatePassword(updatePasswordDTO);
        return Result.success();
    }
}
